package com.lfg.leetcode.leetcode200;

public class No223computeArea {

    public static void main(String[] args) {
        int ret = computeArea(-3, 0, 3, 4, 0, -1, 9, 2);
        System.out.println(ret);
    }

    public static int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int ret = Math.abs((A - C) * (B - D)) + Math.abs((E - G) * (F - H));
        if (E > C || G < A || H < B || F > D) {
            return ret;
        }
        int a, b, c, d;
        if (A <= E) {
            a = E;
        } else {
            a = A;
        }
        if (G <= C) {
            c = G;
        } else {
            c = C;
        }
        if (B <= F) {
            b = F;
        } else {
            b = B;
        }
        if (H <= D) {
            d = H;
        } else {
            d = D;
        }
        return ret - Math.abs((a - c) * (b - d));
    }
}
